﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
String.prototype.trim = function () { return this.replace(/^\*|\s*$/gi, "") }
var PromptInfo_TimerInterval;
var PromptInfo_TimerConter = 4;
var clientMsgID = "ClientMsg";
var isApplyClientMsg = true;

$(function () {
    // 操作提示关闭 
    $(".close").click(
			function () {
			    $(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
			        $(this).slideUp(400);
			    });
			    return false;
			}
		);
    $("#checkBoxAll").click(function () {

        SelectAll('checkBoxAll', 'ListInfo');
    });
    // 验证
    $(".Verification").each(function () {
        $(this).blur(function () {
            var reg = new RegExp($(this).attr("RegExp"));
            if (!reg.test($(this).val().trim())) {
                if ($(this).parent().find(".error").length == 0) {
                    $(this).parent().append("<span class=\"input-notification error  png_bg\">" + $(this).attr("ErrorMsg") + "</span>");
                }
            } else {
                $(this).parent().find(".error").remove();
            }
        });
    });

    $("#ListInfo tr td[class='op'] input[type='image']").click(function () {
        return window.confirm("是否确定删除当前记录？");
    });

    $("#theForm").submit(function () {
        var isTrue;

        isTrue = true;
        $(".Verification").each(function () {
            var reg = new RegExp($(this).attr("RegExp"));
            if (!reg.test($(this).val().trim())) {
                if ($(this).parent().find(".error").length == 0) {
                    $(this).parent().append("<span class=\"input-notification error  png_bg\">" + $(this).attr("ErrorMsg") + "</span>");
                }
                isTrue = false;
            }
        });

        return isTrue;
    });
});
// 全选或全部取消
function SelectAll(id, containerID) {
 
    if ($("#" + id).attr("checked")) {
        $("#" + containerID).find("input[type='checkbox']").each(function () {
            $(this).attr("checked", "checked");
           
        }
                );
    }
    else {
        $("#" + containerID).find("input[type='checkbox']").each(function () {
            $(this).removeAttr("checked");
        }
                );
    }
}
// 显示提示信息
function displayPromptInfo(isTrue, isClose) {
    PromptInfo_IsHidenMainBody = isTrue;
    PromptInfo_TimerConter = 4;

    if (isTrue) {
        $(function () { $("#MainBody").css("display", "none"); });
    } else {
        if (isClose) {
            PromptInfo_TimerInterval = window.setInterval(PromptInfoTimer, 1000);
        }
    }
}

// 提示信息关闭倒计时
function PromptInfoTimer() {
    PromptInfo_TimerConter--;
    $("#PromptInfo_Timer").text(PromptInfo_TimerConter);
    if (PromptInfo_TimerConter < 0) {
        if (isApplyClientMsg == true) {
            $("#" + clientMsgID).empty();
        } else {
            $("#PromptInfo").remove();
        }
        window.clearInterval(PromptInfo_TimerInterval);
    }
}

// 操作提示
function showMsg(msg, type, isHideMainBody, isClose) {
    var msgContent;

    switch (type) {
        case "e":
            msgContent = " <div class=\"notification error png_bg\">";
            msgContent += "<a href=\"#\" class=\"close\"><img src=\"/skin/images/cross_grey_small.png\" title=\"关闭\" alt=\"关闭\" /></a>";
            msgContent += "<div>";
            msgContent += msg;
            msgContent += " </div>";
            msgContent += "<span id=\"PromptInfo_Timer\" class=\"timer\"></span>";
            msgContent += "</div>";
            $("#" + clientMsgID).html(msgContent);
            displayPromptInfo(isHideMainBody, isClose);
            break;
        case "s":
            msgContent = " <div class=\"notification success png_bg\">";
            msgContent += "<a href=\"#\" class=\"close\"><img src=\"/skin/images/cross_grey_small.png\" title=\"关闭\" alt=\"关闭\" /></a>";
            msgContent += "<div>";
            msgContent += msg;
            msgContent += " </div>";
            msgContent += "<span id=\"PromptInfo_Timer\" class=\"timer\"></span>";
            msgContent += "</div>";
            $("#" + clientMsgID).html(msgContent);
            displayPromptInfo(isHideMainBody, isClose);
            break;
        case "w":
            msgContent = " <div class=\"notification attention png_bg\">";
            msgContent += "<a href=\"#\" class=\"close\"><img src=\"/skin/images/cross_grey_small.png\" title=\"关闭\" alt=\"关闭\" /></a>";
            msgContent += "<div>";
            msgContent += msg;
            msgContent += " </div>";
            msgContent += "<span id=\"PromptInfo_Timer\" class=\"timer\"></span>";
            msgContent += "</div>";
            $("#" + clientMsgID).html(msgContent);
            displayPromptInfo(isHideMainBody, isClose);
            break;
        case "p":
            msgContent = " <div class=\"notification information png_bg\">";
            msgContent += "<a href=\"#\" class=\"close\"><img src=\"/skin/images/cross_grey_small.png\" title=\"关闭\" alt=\"关闭\" /></a>";
            msgContent += "<div>";
            msgContent += msg;
            msgContent += " </div>";
            msgContent += "<span id=\"PromptInfo_Timer\" class=\"timer\"></span>";
            msgContent += "</div>";
            $("#" + clientMsgID).html(msgContent);
            displayPromptInfo(isHideMainBody, isClose);
            break;
    }
}

// 获取URL参数数组
function getUrlParam(url) {
    var arrParam = new Array();
    var counter = 0;

    if (url.indexOf("?") > -1) {
        if (url.split("?").length == 2 && url.split("?")[1].trim() != "") {
            var param = url.split("?")[1].split("&");

            for (var i = 0; i < param.length; i++) {
                if (param[i].split("=").length == 2) {
                    arrParam[counter] = { name: param[i].split("=")[0], value: param[i].split("=")[1] };
                    counter++;
                }
            }
        }
    }

    return arrParam;
}

// 查找参URL参数
function lookArrayValue(arrParam, key) {
    var value = null;

    for (var i = 0; i < arrParam.length; i++) {
        if (arrParam[i].name == key) {
            value = arrParam[i].value;
            break;
        }
    }

    return value;
}

// 下拉列表初始赋值
function initSelectValue(seID, value, isValue) {
    var selObj = document.getElementById(seID);
    for (var i = 0; i < selObj.options.length; i++) {
        if (isValue) {
            if (selObj.options[i].value == value) {
                selObj.options[i].selected = true;
                break;
            }
        } else {
            if (selObj.options[i].text == value) {
                selObj.options[i].selected = true;
                break;
            }
        }
    }
}

function Refresh() {
    location.href = location.href;
}

function IsNumeric(obj) {
 
    obj.value = obj.value.replace(/\D/g, '');
}

function NumericMinMax(obj, min, max) {
    var str = /^[1-7]$/;


    if (!new RegExp(obj.value).test(str)) {
        alert('数据有误');
    }
}

function checkDel(containerID) {
    if (ConfirmCheckSelect(containerID)) {
        if (confirm('确认要将选中的数据删除吗？')) {
            return true;
        }
    }
    return false;
}

function checkStop(containerID) {
    if (ConfirmCheckSelect(containerID)) {
        if (confirm('确认要将选中的数据停用吗？')) {
            return true;
        }
    }
    return false;
}

function ConfirmCheckSelect(containerID) {
    var isTrue = false;
    $("#" + containerID).find("input[type='checkbox']").each(function () {

        if ($(this).attr("checked")) {
            isTrue = true;
        }
    });

    if (!isTrue) {

        alert('请选择要操作的记录！');

    }
    return isTrue;
}